/**
 * 
 */
package com.sx.feesunit.biz.impl;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;




import com.sx.feesunit.biz.IAreaBiz;
import com.sx.feesunit.biz.IUserUnitBiz;
import com.sx.feesunit.biz.PoiUserExcel;
import com.sx.feesunit.dao.IAreaDao;
import com.sx.feesunit.dao.IUserUnitDao;
import com.sx.feesunit.entity.AreaEntity;
import com.sx.feesunit.entity.UserUnitEntity;
import com.sx.feesunit.exception.SXException;
import com.sx.util.poi.PoiExcel2k3Helper;
import com.sx.util.poi.PoiExcel2k7Helper;
import com.sx.util.poi.PoiExcelHelper;

import org.apache.poi.ss.usermodel.Sheet;
/**
 * @author Administrator
 *
 */
public class UserUnitBiz implements IUserUnitBiz {

	private IUserUnitDao iuserunitdao;
	private Log log = LogFactory.getLog(this.getClass());
	/**
	 *从Excel中获取用户数据信息 
	 **/
	public List<UserUnitEntity> getUserUnitInfoFormExcel(File file,String filename) throws Exception{
		List<UserUnitEntity> list = new ArrayList<UserUnitEntity>();
		try {
			PoiUserExcel excel;
			if(filename.indexOf(".xlsx")!=-1) {
				excel = new PoiUser2k7Excel();
			}else {
				excel = new PoiUser2k3Excel();
			}
			list = excel.findUserInfos(file);
//			for (UserUnitEntity user : list) {
//				addUserUnitInfo(user);
//			}
		} catch (Exception e) {
			log.error("从Excel中获取用户信息",e);
			throw new SXException(e);
		}
		return list;
	}
	/**
	 *查询用户是否欠费数据信息报错 
	 **/
	public List<UserUnitEntity> findUserUnitInfoIsOwed(UserUnitEntity userunit) throws Exception {
		// TODO Auto-generated method stub
		try {
			return iuserunitdao.findUserUnitInfoIsOwed(userunit);
		} catch (Exception e) {
			log.error("查询用户是否欠费数据信息报错",e);
			throw new SXException(e);
		}
	}
	
	public Integer addUserUnitInfo(UserUnitEntity userunit) throws Exception {
		// TODO Auto-generated method stub
		try {
			return iuserunitdao.addUserUnitInfo(userunit);
		} catch (Exception e) {
			log.error("新增用户信息报错",e);
			throw new SXException(e);
			// TODO: handle exceptio
		}
	}

	public boolean deleteUserUnitInfo(UserUnitEntity userunit) throws Exception {
		try {
			return iuserunitdao.deleteUserUnitInfo(userunit);
		} catch (Exception e) {
			log.error("删除用户信息报错",e);
			throw new SXException(e);
			// TODO: handle exceptio
		}
	}

	public List<UserUnitEntity> findUserUnitInfo(UserUnitEntity userunit)
			throws Exception {
		// TODO Auto-generated method stub
		try {
			return iuserunitdao.findUserUnitInfo(userunit);
		} catch (Exception e) {
			log.error("查询用户数据信息报错",e);
			throw new SXException(e);
		}
	}

	public List<UserUnitEntity> findUserUnitInfoByAndCondiction(
			UserUnitEntity userunit) throws  SXException {
		try {
			return iuserunitdao.findUserUnitInfoByAndCondiction(userunit);
		} catch (Exception e) {
			log.error("查询小区And条件报错",e);
			throw new SXException(e);
		}
	}

	public List<UserUnitEntity> findUserUnitInfoByOrCondiction(
			UserUnitEntity userunit) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean updateUserUnitInfo(UserUnitEntity userunit) throws Exception {
		try {
			return iuserunitdao.updateUserUnitInfo(userunit);
		} catch (Exception e) {
			log.error("修改小区报错",e);
			throw new SXException(e);
			// TODO: handle exceptio
		}
	}

	/**
	 * @return the iuserunitdao
	 */
	public IUserUnitDao getIuserunitdao() {
		return iuserunitdao;
	}

	/**
	 * @param iuserunitdao the iuserunitdao to set
	 */
	public void setIuserunitdao(IUserUnitDao iuserunitdao) {
		this.iuserunitdao = iuserunitdao;
	}

	
	
}
